
/**
 * 默认输入
 */
const DefaultInput = {
    Primary: {
        X: ["a", "d"], // -1 1
        Y: ["w", "S"]  // -1 1 
    },
    Secondary: {
        X: ["left", "right"],
        Y: ["up", "down"]
    },
    Jump: "space",
    Fire: "mouse_left",
    Change: "c"
}

/**
 * 输入配置表
 */
export class InputConfig {
    constructor (config: any) {
        for (const key in config) {
            if (key != "Primary" && key != "Secondary") {
                this.controlKeys.set(key, config[key])
            }
        }
    }

    public primary = DefaultInput.Primary;
    public secondary = DefaultInput.Secondary;
    public controlKeys: Map<string, string> = new Map;

    /**
     * 设置控制按键
     * @param control 
     * @param key 
     */
    public setControlKey (control: string, key: string) {
        // @ts-ignore
        this[control] = key;
    }

    /**
     * 获取主摇杆输入
     * @returns 
     */
    public getPrimary () {
        return this.primary;
    }

    /**
    * 获取副摇杆输入
    * @returns 
    */
    public getSecondary () {
        return this.secondary;
    }

    /**
     * 获取控制键
     * @param control 
     * @returns 
     */
    public getControlKey (control: string) {
        if (this.controlKeys.hasOwnProperty(control)) {
            return this.controlKeys.get(control)
        }
        return "";
    }
}

export const inputConfig = new InputConfig(DefaultInput);